package com.example.lenovo.a203_yhy_ordering_3.model;

import com.example.lenovo.a203_yhy_ordering_3.beans.UserCollectFoodBean;
import com.example.lenovo.a203_yhy_ordering_3.beans.UserCollectShopBean;
import com.example.lenovo.a203_yhy_ordering_3.iface.UserCollectShopIface;
import com.example.lenovo.a203_yhy_ordering_3.listener.UserCollectShopListener;
import com.example.lenovo.a203_yhy_ordering_3.service.UserCollectFoodService;
import com.example.lenovo.a203_yhy_ordering_3.service.UserCollectShopService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by lenovo on 2018/12/5.
 */

public class UserCollectShopModel implements UserCollectShopIface{

    private Retrofit retrofit;

    public UserCollectShopModel(){
        retrofit = new Retrofit.Builder()
                .baseUrl("http://172.24.10.175:8080/foodService/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    @Override
    public void getUserCollectShopResult(int user_id, int shop_id, final UserCollectShopListener userCollectShopListener) {
        UserCollectShopService userCollectShopService = retrofit.create(UserCollectShopService.class);

        Call<UserCollectShopBean> userCollectShopCall = userCollectShopService.userCollectShop(user_id,shop_id);

        userCollectShopCall.enqueue(new Callback<UserCollectShopBean>() {
            @Override
            public void onResponse(Call<UserCollectShopBean> call, Response<UserCollectShopBean> response) {
                if(response!=null)
                    userCollectShopListener.onResponse(response.body());
                else
                    userCollectShopListener.onFail("获取店铺收藏失败");
            }

            @Override
            public void onFailure(Call<UserCollectShopBean> call, Throwable t) {
                userCollectShopListener.onFail(t.toString());
            }
        });
    }
}
